package com.mayikt.controller;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

import static com.mayikt.basic.Constants.MESSAGE_QUEUE;


@Component
public class BasicConsumer {

    /**
     * 监听队列回调的方法
     *
     * @param msg
     */
    @RabbitHandler
    @RabbitListener(queues = MESSAGE_QUEUE)
    public void smsProcess(Message msg, Channel channel) throws IOException {
//        try {
//            Thread.sleep(500);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
        System.out.println("短信消费者消息msg:" + msg);
        channel.basicAck(msg.getMessageProperties().getDeliveryTag(), false);
    }


    @RabbitHandler
    @RabbitListener(queues = MESSAGE_QUEUE)
    public void emailProcess(Message msg, Channel channel) throws IOException {
        System.out.println("邮件消费者消息msg:" + msg);
        channel.basicAck(msg.getMessageProperties().getDeliveryTag(), false);
    }
}
